import { CreatePeerCarDto } from '@/pc/peer-car/dto/create-peer-car.dto';
import { PeerCarService } from '@/pc/peer-car/peer-car.service';
import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { LockPeerDto } from './dto/lock-peer-dto';
import { WxPeerCarService } from './wx-peer-car.service';

@ApiTags('小程序同行车源')
@Controller('wxpeercar')
export class WxPeerCarController {
  constructor(private readonly wxPeerCarService: WxPeerCarService, private readonly peerCarService: PeerCarService) {}

  @Post()
  async create(@Body() body: CreatePeerCarDto) {
    return await this.peerCarService.create(body)
  }

  @Get('page')
  async findPage(@Query() query: any) {
    return await this.peerCarService.findPage(query)
  }

  @Get()
  async findOne(@Query() query: { id: string }) {
    return await this.peerCarService.findOne(query.id)
  }

  @Get('user')
  async findByUser(@Query() query: { userId: string }) {
    return await this.wxPeerCarService.findByUser(query.userId)
  }


  @Get('img')
  async findPeerImg(@Query() query: { peerId: string }) {
    return await this.peerCarService.findPeerImg(query.peerId)
  }

  @Post('img')
  async createPeerImg(@Body() body: { url: string, peerId: string }) {
    return await this.peerCarService.createPeerImg(body)
  }

  @Post('lock')
  async lockPeer(@Body() dto: LockPeerDto) {
    return await this.wxPeerCarService.lockPeer(dto)
  }

  @Get('expire/:id')
  async checkChannelLockExpire(@Param('id') id: string) {
    return await this.wxPeerCarService.checkPeerLockExpire(id)
  }

  @Get('checkOut/:id')
  async checkOuted(@Param('id') id: string) {
    return await this.wxPeerCarService.checkOuted(id)
  }
}
